﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using MvcEngine.Core;
using MvcEngine.Core.Extensions;
using MvcEngine.Mvc.Extensions;
using MvcEngine.Contact.Models;
using MvcEngine.Core.Helpers;
using MvcEngine.Mvc.ModelBinders;

namespace MvcEngine.Contact.ModelBinders
{
    public class ContactModelBinder : ModelBinderBase
    {
        public override object Bind(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            HttpRequestBase request = controllerContext.HttpContext.Request;
            MessageData msg = new MessageData();
            msg.Email = request.Form.Get("Email").HtmlEncode();
            msg.Message = request.Form.Get("Message").HtmlEncode();
            msg.Name = request.Form.Get("Name").HtmlEncode();
            msg.Subject = request.Form.Get("Subject").HtmlEncode();

            Validate(msg, controllerContext);
            return msg;
        }
    }
}
